﻿using MediatR;
using MS.Data.API.Write.Applicant.Command.User;
using MS.Data.Domain;
using MS.Data.ErrorCode;
using MS.Data.Infratructrue.Istanbul;

namespace MS.Data.API.Write.Applicant.CommandHandel.User
{
    public class FaningUserCommandHandel : IRequestHandler<FaningUserCommand, APIResult<List<Domain.User>>>
    {
        IBaseRepository<Domain.User> userRep;

        public FaningUserCommandHandel(IBaseRepository<Domain.User> userRep)
        {
            this.userRep = userRep;
        }

        public Task<APIResult<List<Domain.User>>> Handle(FaningUserCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Domain.User>> result = new APIResult<List<Domain.User>>();
            result.code = APIEnum.更新成功;
            result.mes = APIEnum.更新成功.ToString();

            var list = userRep.GetAll().Where(s => s.UserId == request.UserId);

            result.data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
